package com.itheima.mall.controller.umsController;


import com.itheima.mall.commons.R;
import com.itheima.mall.service.umsService.UmsAdminService;
import com.itheima.pojo.ums.UmsAdmin;
import com.itheima.vo.ums.UmsAdminVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/admin")
public class UmsAdminController {


    @Autowired
    private UmsAdminService umsAdminService;

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 1.登录后返回token
     * @param map
     * @return
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map<String,String> map){
        return umsAdminService.login(map);
    }

    /**
     * 2.登出（退出登录）需要清除redis中的token
     * @return
     */
    @PostMapping("/logout")
    public ResponseEntity logout(){
        //删除redis中的token
        redisTemplate.delete("ID");
        return ResponseEntity.ok(null);
    }

    /**
     * 3.刷新token
     * @return
     */
    @GetMapping("/refreshToken")
    public ResponseEntity refreshToken(){
        return ResponseEntity.ok(null);
    }

    /**
     * 4.删除指定用户信息
     * @return
     */
    @PostMapping("/delete/{id}")
    public ResponseEntity deleteById(@RequestBody UmsAdmin umsAdmin){
        umsAdminService.deleteById(umsAdmin);
        return ResponseEntity.ok(null);

    }

    /**
     *  5.获取当前登录用户信息
     * @return
     */
   @GetMapping("/info")
    public R info(){
       UmsAdminVo vo =umsAdminService.info();
       return R.ok(vo);
    }

}
